<?php

/**
 * This is the model class for table "tbl_job".
 *
 * The followings are the available columns in table 'tbl_job':
 * @property integer $id
 * @property integer $user_id
 * @property string $name
 * @property integer $status
 * @property integer $statuspost
 * @property integer $subjobtype_id
 * @property string $timeend
 * @property string $timepost
 * @property string $timecontract
 * @property integer $statustime
 * @property string $jobdesc
 * @property string $fileattached
 * @property integer $id_winner
 * @property integer $viewed
 * @property integer $budget_id
 *
 * The followings are the available model relations:
 * @property Bidjob[] $bidjobs
 * @property Comment[] $comments
 * @property Feedback[] $feedbacks
 * @property Budget $budget
 * @property Users $user
 * @property SubJobtype $subjobtype
 * @property Users $idWinner
 * @property JobSkill[] $jobSkills
 */
class Job extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Job the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'tbl_job';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('user_id, name, status, subjobtype_id, timeend,jobdesc, id_winner, viewed, budget_id', 'required'),
            array('user_id, status, statuspost, subjobtype_id, id_winner, viewed, budget_id', 'numerical', 'integerOnly'=>true),
            array('name', 'length', 'max'=>200),
            array('fileattached', 'length', 'max'=>50),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, user_id, name, status, statuspost, subjobtype_id, timeend, timepost, jobdesc, fileattached, id_winner, viewed, budget_id', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'bidjobs' => array(self::HAS_MANY, 'Bidjob', 'job_id'),
            'comments' => array(self::HAS_MANY, 'Comment', 'job_id'),
            'feedbacks' => array(self::HAS_MANY, 'Feedback', 'job_id'),
            'inboxes' => array(self::HAS_MANY, 'Inbox', 'job_id'),
            'budget' => array(self::BELONGS_TO, 'Budget', 'budget_id'),
            'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
            'subjobtype' => array(self::BELONGS_TO, 'SubJobtype', 'subjobtype_id'),
            'idWinner' => array(self::BELONGS_TO, 'Users', 'id_winner'),
            'jobSkills' => array(self::HAS_MANY, 'JobSkill', 'job_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'user_id' => 'User',
            'name' => 'Name',
            'status' => 'Status',
            'statuspost' => 'Statuspost',
            'subjobtype_id' => 'Subjobtype',
            'timeend' => 'Timeend',
            'timepost' => 'Timepost',
            'jobdesc' => 'Jobdesc',
            'fileattached' => 'Fileattached',
            'id_winner' => 'Id Winner',
            'viewed' => 'Viewed',
            'budget_id' => 'Budget',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('user_id',$this->user_id);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('status',$this->status);
        $criteria->compare('statuspost',$this->statuspost);
        $criteria->compare('subjobtype_id',$this->subjobtype_id);
        $criteria->compare('timeend',$this->timeend,true);
        $criteria->compare('timepost',$this->timepost,true);
        $criteria->compare('jobdesc',$this->jobdesc,true);
        $criteria->compare('fileattached',$this->fileattached,true);
        $criteria->compare('id_winner',$this->id_winner);
        $criteria->compare('viewed',$this->viewed);
        $criteria->compare('budget_id',$this->budget_id);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}